package executors;

import java.util.ArrayList;

import objects.Command;
import objects.Event;
import objects.Result;
import objects.SortedEventList;

public class SubAddExecutor {
	public static Result execute(Command command, SortedEventList data,
			SortedEventList completeTasks) {
		Event task = new Event();
		ArrayList<Event> list = new ArrayList<Event>();
        int id = command.getId();
        boolean isSuccessful = false;
        
        try {
        	task.setDetails(command.getDetail());
        	task.setEndDate(command.getEndDate());
        	task.setStartDate(command.getStartDate());
        	task.setPriority(command.getPriority());
        	
               for (int i = 0; i<data.size(); i++){
            	   if (data.get(i).getId()==id){
            		   isSuccessful = data.get(i).getSubTasks().add(task) && list.add(task);
            		   break;
            	   }  
               }    
               return new Result(isSuccessful, list);
               
        } catch (Exception e){
                return new Result(false, list, null, e.toString());
	}
	}
}
